package com.demo.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
@MapperScan("com.demo.mapper")
public class MybatisConfig {
    //    1. 表明身份  @Component
//    2. 扫描mapper包，生成mapper实现类 @MapperScan("com.demo.mapper")
//    3. 负责调用druid创建SqlSessionFactoryBean，创建一个方法SSFB,通过形参的方式，将druid DataSource注入到方法体中
//    4. 千万不要忘记，写@Bean
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource);
        return sessionFactoryBean;
    }


}
